<template v-cloak>
  <view class="container">
    <view class="content">
      <view class="hd" style="transform: rotateZ(deg)">
        <view class="logo">
          <image
            style="width: 100%; height: 100%"
            src="/static/logo.png"
            mode="widthFix"
          ></image>
        </view>
      </view>
      <view class="smalltitle"> 欢迎访问前端知识小程序 </view>
      <view class="bd">
        <view class="radio flex">
          <u-checkbox-group>
            <u-checkbox
              :label-size="24"
              active-color="#8486f8"
              :icon-size="22"
              v-model="checked"
              shape="circle"
            >
              我已阅读同意前端知识</u-checkbox
            >
          </u-checkbox-group>
          <text class="auth" @click="nav">《授权协议》</text>
        </view>
        <view class="confirm-btn">
          <!-- <button open-type="getUserInfo" lang="zh_CN" @click="">关注一下~</button> -->

          <u-button
            :ripple="true"
            ripple-bg-color="#888cff"
            :custom-style="customStyle"
            @click="getUserProfile"
          >
            授权登录</u-button
          >
        </view>
        <view class="confirm-btn">
          <u-button
            :ripple="true"
            :custom-style="lookStyle"
            plain
            @click="goHome"
            >随便看看</u-button
          >
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      checked: false,
      customStyle: {
        background: "#8486f8",
        color: "#fff",
        fontSize: "20upx",
        fontWeight: "600",
      },
      lookStyle: {
        color: "#999999",
        fontSize: "20upx",
        fontWeight: "600",
      },
    }
  },
  onLoad() {
    this.login()
  },
  methods: {
    goHome() {
      uni.switchTab({
        url: "/pages/index/index",
      })
    },
    nav() {
      uni.navigateTo({
        url: "/pages/mine/auth/auth",
      })
    },
    // 微信授权
    getUserProfile(e) {
      let _self = this
      if (_self.checked == false) {
        wx.showToast({
          title: "请您阅读授权协议",
          icon: "none",
          duration: 2000,
          mask: true,
        })
        return
      }
      uni.getUserProfile({
        desc: "用于完善会员资料", // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: res => {
          let data = {
            encryptedData: res.encryptedData,
            iv: res.iv,
            sessionKey: uni.getStorageSync("session_key"),
            openId: uni.getStorageSync("openid"),
          }
          // _self.$store.dispatch("user/login", data).then(res => {
          //   uni.setStorageSync("avatar", res.data.avatarUrl)
          //   uni.setStorageSync("nickname", res.data.nickName)
          //   uni.setStorageSync("token", res.token)
          //   uni.switchTab({
          //     url: "/pages/pxc/pxc",
          //   })
          // })
        },
      })
    },
    // 进入页面 使用uni.login方法 获取到code 通过code拿到session_key、open_id
    login() {
      let _self = this
      uni.login({
        provider: "weixin",
        success: function (loginRes) {
          let data = { code: loginRes.code }
          _self.$store.dispatch("user/code", data).then(res => {
            uni.setStorageSync("openid", res.openid)
            uni.setStorageSync("session_key", res.session_key)
          })
        },
      })
    },
  },
}
</script>
<style>
.u-btn--default {
  color: #606266;
  border-color: transparent;
  background-color: #ffffff;
}
</style>
<style lang="scss" scoped>
/* pages/subPack/loading/loadPage.wxss */
.container {
  background: #8486f8;
  align-items: stretch;
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

.content {
  flex: 1;
  display: flex;
  position: relative;
  z-index: 10;
  padding-top: 30vw;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding-bottom: 450rpx;
  background: -webkit-gradient(
    linear,
    left top,
    left bottom,
    from(rgba(244, 244, 244, 0)),
    color-stop(0.1, #f4f4f4),
    to(#f4f4f4)
  );
  opacity: 0;
  transform: translate3d(0, 100%, 0);
  animation: rise 3s cubic-bezier(0.19, 1, 0.22, 1) 0.25s forwards;
}

@keyframes rise {
  0% {
    opacity: 0;
    transform: translate3d(0, 100%, 0);
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 1;
    transform: translate3d(0, 450rpx, 0);
  }
}

// .title {
//   position: absolute;
//   top: 0;
//   left: 50%;
//   width: 100%;
//   height: 200upx;
//   font-family: Consolas, "Courier New", monospace;
//   transform: translateX(-50%);
//   animation: show 2.5s cubic-bezier(0.19, 1, 0.22, 1) 0.5s forwards;
//   text-align: center;
//   font-size: 30upx;
//   font-weight: bold;
//   color: #fff;
//   line-height: 140upx;
// }

.smalltitle {
  // position: absolute;
  // top: 50rpx;
  // left: 50%;
  // width: 600rpx;
  // height: 200rpx;
  // margin-left: -300rpx;
  opacity: 0;
  animation: show 2.5s cubic-bezier(0.19, 1, 0.22, 1) 0.5s forwards;
  text-align: center;
  font-size: 26rpx;
  color: #fff;
  // line-height: 140rpx;
  -webkit-text-stroke: 3rpx #8486f8;
  color: transparent;
  background-clip: text;
  text-shadow: 3rpx 3rpx 3rpx #8486f8;
  z-index: 99;
}

@keyframes show {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 0.95;
  }
}

.hd {
  position: absolute;
  top: 0;
  left: 50%;
  width: 1000rpx;
  margin-left: -500rpx;
  height: 200rpx;
  transition: all 0.35s ease;
}

.logo {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 200rpx;
  width: 160rpx;
  height: 160rpx;
  margin-left: -80rpx;
  animation: sway 10s ease-in-out infinite;
  opacity: 0.95;
  overflow: hidden;
  border-radius: 80rpx;
}

@keyframes sway {
  0% {
    transform: translate3d(0, 20rpx, 0) rotate(-15deg);
  }

  17% {
    transform: translate3d(0, 0rpx, 0) rotate(25deg);
  }

  34% {
    transform: translate3d(0, -20rpx, 0) rotate(-20deg);
  }

  50% {
    transform: translate3d(0, -10rpx, 0) rotate(15deg);
  }

  67% {
    transform: translate3d(0, 10rpx, 0) rotate(-25deg);
  }

  84% {
    transform: translate3d(0, 15rpx, 0) rotate(15deg);
  }

  100% {
    transform: translate3d(0, 20rpx, 0) rotate(-15deg);
  }
}

.wave {
  position: absolute;
  z-index: 3;
  right: 0;
  bottom: 0;
  opacity: 0.725;
  height: 260rpx;
  width: 2250rpx;
  animation: wave 10s linear infinite;
}

.wave-bg {
  z-index: 1;
  animation: wave-bg 10.25s linear infinite;
}

@keyframes wave {
  from {
    transform: translate3d(125rpx, 0, 0);
  }

  to {
    transform: translate3d(1125rpx, 0, 0);
  }
}

@keyframes wave-bg {
  from {
    transform: translate3d(375rpx, 0, 0);
  }

  to {
    transform: translate3d(1375rpx, 0, 0);
  }
}

.bd {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  animation: bd-rise 2s cubic-bezier(0.23, 1, 0.32, 1) 0.75s forwards;
  opacity: 0;
  margin-top: 18%;
}

@keyframes bd-rise {
  from {
    opacity: 0;
    transform: translate3d(0, 60rpx, 0);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

form {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
}

.input-group {
  display: flex;
  align-items: center;
  padding: 25rpx 10rpx;
  margin: 40rpx 3%;
  background: #fff;
  border-radius: 5px;
  border: 2px solid #f4f4f4;
  transition: all 0.25s ease-in-out;
}

.input-group.active {
  border: 2px solid #7acfa6;
}

.input-label {
  color: #888;
  font-size: 13pt;
  height: 25rpx;
  line-height: 25rpx;
  padding: 0 25rpx;
  border-right: 1px solid #d8d8d8;
}

.input-group input,
.input-group picker {
  flex: 1;
  font-size: 13pt;
  min-height: 52rpx;
  height: 52rpx;
  line-height: 52rpx;
  padding: 0 25rpx;
}

.input-placeholder,
.input-group picker.placeholder {
  color: #ccc;
}

.login-help {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 30rpx;
  font-size: 10pt;
  color: #bbb;
}

.login-help-img {
  width: 11pt;
  height: 11pt;
  margin: 0 5rpx;
}

.confirm-logo {
  font-size: 24upx;
  line-height: 200px;
  height: 85rpx;
  text-align: center;
}

.confirm-btn {
  background: #8486f8;
  color: #fff;
  text-align: center;
  border-radius: 50px;
  // margin: 50% 20% 30% 20%;
  margin: 0 40upx 20upx;
  font-size: 24upx;
}
.radio {
  padding: 0 40upx;
  margin-bottom: 10upx;
}

.help {
  position: absolute;
  z-index: 100;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 80%;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 0 50px rgba(22, 22, 22, 0.35);
  transform: translate3d(0, -400rpx, 0);
}

.box-hd {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100rpx;
  border-bottom: 1px solid #eee;
}

.box-title {
  font-size: 13pt;
}

.box-close {
  position: absolute;
  right: 20rpx;
  width: 35rpx;
  height: 35rpx;
  padding: 15rpx;
}

.box-bd {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 15rpx 40rpx 30rpx;
}

.help-q {
  color: #999;
  font-size: 11pt;
  line-height: 200%;
  margin-top: 5rpx;
}

.help-a {
  text-indent: 1em;
  line-height: 160%;
  display: flex;
  flex-direction: column;
}

.help-a text {
  word-break: break-all;
}

/**登录动画**/
.login_video {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: 750rpx;
  margin-left: -375rpx;
  height: 1334rpx;
  margin-top: -667rpx;
}

.video_hidden {
  visibility: hidden;
}

page .wx-video-bar {
  display: none;
}

.copyright {
  font-size: 28rpx;
  color: #999;
  position: fixed;
  top: 85%;
  left: 0;
  right: 0;
  padding: 30rpx;
  text-align: center;
}

.copyright text {
  font-size: 28rpx;
  color: #118fff;
  margin-left: 15rpx;
}
.auth {
  color: #8486f8;
  font-size: 24upx;
}
</style>
